﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Collections;
using System.Data.SqlClient;
using System.Windows.Forms;
using HREDU.Hoang_Tuan.Classes;

namespace HREDU.Hoang_Tuan
{
    public partial class frmCapNhatPhanMem : Form
    {
        public frmCapNhatPhanMem()
        {
            InitializeComponent();
        }

        private void btBrowse_Click(object sender, EventArgs e)
        {
            //mo form cho nguoi ta chon co so du lieu
            OpenFileDialog1.Filter = "Backup File(*.txt;*.sql)|*.txt;*.sql|All files (*.*)|*.*";
            OpenFileDialog1.ShowDialog();
            txtFilePath.Text = OpenFileDialog1.FileName;
            string readText = File.ReadAllText(txtFilePath.Text, Encoding.UTF8);
            richTextBoxNoiDung.Text = readText;
        }

        private void btDongY_Click(object sender, EventArgs e)
        {
            string strSQL = "";
            if (File.Exists(txtFilePath.Text))
            {
                 StreamReader sr = new StreamReader(txtFilePath.Text);
                 
                 string line;
                 line = sr.ReadLine();
                 do
                 {
                     if (line.Trim().ToLower() == "go")
                     {
                         if (strSQL != "")
                         {
                             MITI.BaseDB.Instance.ExecSql_NoneQuery(strSQL);
                             strSQL = "";
                         }
                     }
                     else if (line.Trim().ToLower() != "")
                        strSQL += line + " ";
                    line = sr.ReadLine();
                 }
                 while (!(line == null));
                 sr.Close();
                 MessageBox.Show("Cập nhật xong.");
            }
        }
    }
}